package top.datacluster.basic.algorithm.leetcode.heap;

import java.util.PriorityQueue;

public class LeetCode40 {

    public int[] getLeastNumbers(int[] arr, int k) {
        PriorityQueue<Integer> heap = new PriorityQueue();
        int[] result = new int[k];
        for (int i = 0; i < arr.length; i++){
            heap.add(arr[i]);
        }
        for (int i = 0; i < k; i++){
            result[i] = heap.poll();
        }
        return result;
    }
}
